import React from 'react'
import style from './style.css'
import style_parent from '../talkItemList/style.css'
import Bottom from "../../../component/bottom";
import {GET_TALK_LIST} from "../../../api/talk";
import pageRedux from "../../pageRedux";
import {getHistory} from "../../../util/uitls";
import {createIOuuid} from "../../../util/socket";

class TalkItem extends React.Component {
    constructor(props) {
        super(props);
        this.state = {visible: props.visible,};
    };


    componentWillReceiveProps(nextProps) {
    }

    componentDidMount() {
    }


    onClose() {
        this.props.onClose()
    }

    onClick() {
        var user = this.props.you
        this.props.setStore("app.activeTalkUser", user)
        getHistory().push(`/talk/${user.id}`)
    }

    render() {
        var uuid = createIOuuid(this.props.me.id, this.props.you.id)
        var messages = this.props.getStore(`app.activeTalkUserMessage${uuid}`)
        var lastMessage = ""
        if (messages&&messages.length >= 0) {
            lastMessage = messages[messages.length - 1].message.content
        }

        return <section className={`${style_parent.TalkItem} ${style.TalkItem} ${this.props.isMe ? style.me : 'you'}`}
                        onClick={this.onClick.bind(this)}
        >
            <div className={style.user}>
                <img src={this.props.you.avatar_url} alt=""/>
            </div>
            <div className={style.messageWrapper}>
                <div className={style.name}>
                    {this.props.you.name}
                </div>
                {lastMessage && <div className={style.message}>
                    {lastMessage}
                </div>}

            </div>

        </section>
    }
}

TalkItem.defaultProps = {
    message: '',
    me: {
        avatar_url: "8gax1p1g8xm",
        city: "i7hon2ul3jk",
        gender: 1.8995215743586558,
        id: 2.447134362161079,
        latitude: 3.118338648435844,
        longitude: 1.6737332855981988,
        mobile: "l2y19eim6h7",
        name: "i3paldc4ffm",
        nick_name: "c9kwdq1erk",
        province: "9rgt59y3yho"
    },
    you: {
        avatar_url: "8gax1p1g8xm",
        city: "i7hon2ul3jk",
        gender: 1.8995215743586558,
        id: 2.447134362161079,
        latitude: 3.118338648435844,
        longitude: 1.6737332855981988,
        mobile: "l2y19eim6h7",
        name: "i3paldc4ffm",
        nick_name: "c9kwdq1erk",
        province: "9rgt59y3yho"
    },
    isMe: false
}
export default pageRedux(TalkItem)